//
//  LaunchViewController.swift
//  QNN
//
//  Created by zhenyu on 17/3/30.
//  Copyright © 2017年 qianshengqian. All rights reserved.
//

import UIKit

class LaunchViewController: UIViewController {
  
  weak var launchImageView: UIImageView!
  
  // MARK: - LifeCycle
  override func viewDidLoad() {
    super.viewDidLoad()
    setVeiws()
    // Do any additional setup after loading the view.
    
    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3) { 
      RootController.root()
    }
  }
  
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
  
  deinit {
    debugPrint("LaunchViewController deinit")
  }
  
  // MARK: - SetViews
  func setVeiws() {
    var imageName = ""
    let viewSize = view.bounds.size
    imageName = getLaunchImage(viewSize: viewSize)!
    let imageView = UIImageView(image: UIImage(named: imageName))
    imageView.frame = view.bounds
    view.addSubview(imageView)
  }
  
  // MARK: - Methods
  func getLaunchImage(viewSize: CGSize) -> String? {
    let imageDic = (Bundle.main.infoDictionary! as NSDictionary).value(forKey: "UILaunchImages") as! NSArray
    for dic in imageDic {
      let dict = dic as! NSDictionary
      let size = CGSizeFromString(dict["UILaunchImageSize"] as! String) as CGSize
      if size.equalTo(viewSize) && "Portrait" == dict["UILaunchImageOrientation"] as! String {
        return dict["UILaunchImageName"] as? String
      }
    }
    return ""
  }
}
